import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '../views/Home.vue'
import talk from '../views/talkRoom/list.vue'

const routes = [
  {
    path:'/',
    redirect:'/login'
  },
  {
    path:'/u',
    name:'u',
    component:()=>import('../views/upload.vue')
  },
  {
    path:'/me',
    name:'me',
    component:()=>import('../views/me.vue')
  },
  {
    path:'/qita',
    name:'qita',
    component:()=>import('../views/qita.vue')
  },
  {
    path:'/login',
    name:'login',
    component:()=>import('../views/login/login.vue')
  },
  {
    path:'/register',
    name:'register',
    component:()=>import('../views/login/register.vue')
  },
  {
    path:'/diary_detail',
    name:'diary_detail',
    component:()=>import('../views/diary_detail.vue')
  },
  {
    path:'/add_diary',
    name:'add_diary',
    component:()=>import('../views/add_diary.vue')
  },
  {
    path:'/my',
    name:'my',
    component:()=>import('../views/my/my.vue')
  },
  {
    path:'/my/my_diary',
    name:'my_diary',
    component:()=>import('../views/my/my_diary.vue')
  },
  {
    path:'/my/faceback',
    name:'faceback',
    component:()=>import('../views/my/faceback.vue')
  },
  {
    path:'/user_data',
    name:'user_data',
    component:()=>import('../views/my/user_data.vue')
  },
  // {
  //   path:'/t',
  //   name:'t',
  //   component:()=>import('../views/talk_room.vue')
  // },
  {
    path: '/Home',
    name: 'Home',
    component: Home
  },

  
  {
    path: '/tl',
    name: 'tl',
    component:()=>import('../views/talk/talkList.vue')  
    
  },

  {
    path: '/security_settings',
    name: 'security_settings',
    component:()=>import('../views/my/security_settings.vue')  
  },
  {
    path: '/talk',
    name: 'talk',
    component:talk,
    meta:{
      keep:true
    }
    // children:[
    //   {
    //     path: '/talk/talkList',
    //     name: 'talkList',
    //     component:()=>import('../views/talkRoom/list.vue')  
    //   },
    //   {
    //     path: '/talk/talkRoom',
    //     name: 'talkRoom',
    //     component:()=>import('../views/talkRoom/talkRoom.vue')  
    //   },
    // ]
  }
  
  
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach((to, from,next) => {
  if(to.name=='login'||sessionStorage.getItem('user_token')||to.name=='register'){
    next()
  }else{
    console.log('去登录')
    router.replace('/login')
  }
  
})
export default router
